<?php
namespace x;
class G {
	public static $post = [];
	public static $get = [];
	public static $db = null;
	public static $db1 = null;
	public static $uuid = '';
	public static $front_data = [];
	public static $error_data = [];
	public static $domain_config = [];
	public static $web_site_id = 0;
	public static $m = 'index'; #模块名称
	public static $exts = [];

	//初始化全局变量
	static public function init() {
		self::$post = self::$post ? self::$post : self::filter($_POST);
		self::$get = self::$get ? self::$get : self::filter($_GET);
		//self::$uuid = self::$uuid ? self::$uuid : session_create_id();

		define('DOMAIN', $_SERVER['HTTP_HOST']);
		#一级域名解析, 多模块
		$arr_domain = env('arr_domain');
		if ($arr_domain) {
			if (isset($arr_domain[$_SERVER['HTTP_HOST']])) {
				self::$web_site_id = $arr_domain[$_SERVER['HTTP_HOST']];
			} else {
				self::$web_site_id = current(explode(".", $_SERVER['HTTP_HOST']));
			}
		}
		#数据库
		$db = env('db');
		if (isset($db['host'])) {
			self::$db = Container::get('x\db\driver\Mysqlidb')->init($db);
		}
		$db1 = env('db1');
		if (isset($db1['host'])) {
			self::$db1 = Container::get('x\db\driver\Mysqlidb1')->init($db1);
		}
	}
	//过滤函数
	static public function filter($array = []) {
		//return $array;
		foreach ($array as $key => $var) {
			if (is_string($var)) {
				$var = trim($var);
				$var = htmlspecialchars($var, ENT_QUOTES);
				// if(get_magic_quotes_gpc()){
				//     $var = addslashes($var);
				// }
				$array[$key] = $var;
			}
			if (is_array($var)) {
				$array[$key] = self::filter($var);
			}
		}
		return $array;
	}
}
